﻿@model FlashCards.WebApp.Models.FriendshipsModel

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Friends</h2>

@using(Html.BeginForm())
{
    @Html.TextBox("SearchPattern")
    
    <input type="submit" value="Search" />
}


@if (Model != null)
{
    if (Model.SearchedUsers != null)
    {
        foreach (var searchedUser in Model.SearchedUsers)
        {
            <div>
                
                @Html.DisplayFor(x => searchedUser.Name) @Html.DisplayFor(x => searchedUser.Surname)

                @using(Html.BeginForm("SendFriendshipInvitation", "Friends", new { friendId = searchedUser.UserId}))
                {
                    <input type="submit" value="Invite" />
                }
            </div>
        }
    }

    if(Model.InvitedUsers != null && Model.InvitedUsers.Count > 0)
    {
        <p>Invitations sent</p>

        foreach (var invitedUser in Model.InvitedUsers)
        {
            <div>
                @Html.DisplayFor(x => invitedUser.Name) @Html.DisplayFor(x => invitedUser.Surname)
                @using(Html.BeginForm("ConfirmFriendshipInvitation", "Friends", new { userName = invitedUser.UserName }))
                {
                    <input type="submit" value="Confirm" />
                }
            </div>
        }
    }

    if (Model.Friends != null && Model.Friends.Count > 0)
    {
        <p>Friends</p>
        foreach (var friend in Model.Friends)
        {
            <div>
                <img src='@Url.Action("GetUserAvatar", "Friends", new { userId = friend.UserId })' alt="Avatar" />
                @Html.DisplayFor(x => friend.Name) @Html.DisplayFor(x => friend.Surname)
                @Html.ActionLink("x", "DeleteFriendship", new { friendNick = friend.UserName })
            </div>
        }
    }
    else
    {
        <p>you have no friends</p>
    }
    
    
        
}

